<?php

/* @var $this \yii\web\View */
/* @var $content string */

use yii\helpers\Url;
use yii\helpers\Html;
use common\helpers\Render;
use common\models\Navigator;

?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <?= Html::csrfMetaTags() ?>
    <title><?= $this->context->module->name.' '.Html::encode($this->title) ?></title>
    <?php // $this->head() ?>
    <link rel="stylesheet" href="<?= Url::to('@web/web/static/Font-Awesome-3.2.1/css/font-awesome.css') ?>">
    <link rel="stylesheet" href="<?= Url::to('@web/web/static/css/site.css') ?>">
    <link rel="stylesheet" href="<?= Render::static('flyer/flyer.css') ?>">
    <link rel="stylesheet" href="<?= Render::static('pikaday/pikaday.css') ?>">
    <script src="<?= Url::to('@web/web/static/js/common.js') ?>"></script>
    <script src="<?= Render::static('jquery/jquery-2.0.3.min.js') ?>"></script>
    <script src="<?= Render::static('layer/layer.js') ?>"></script>
    <script src="<?= Render::static('pikaday/pikaday.min.js') ?>"></script>
    <script src="<?= Render::static('art-template/template.js') ?>"></script>
</head>
<body style="background-color:#e5e5e5;">
<?php $this->beginBody() ?>

<script>
    var _drop_down = false;
    $(document).ready(function () {
        //  下拉菜单事件绑定
        $('.down-button').bind('click', function () {
            var dropdown = $(this).parent('.drop-down');
            _drop_down = true;
            if($(dropdown).hasClass('open')) {
                $(dropdown).removeClass('open');
            }
            else {
                $(dropdown).addClass('open');
            }
        });
        //  body点击被触发时，关闭下拉菜单
        $('body').bind('click', function () {
            if(_drop_down) {
                _drop_down = false;
            }
            else {
                $('.drop-down').removeClass('open');
            }
        });
        //  导航切换事件
        $('#navigator .cate').bind('click', function() {
            if ($(this).hasClass('select')) {
                return;
            }
            var id = $(this).data('id');
            if ( ! id) {
                layer.msg('请刷新页面重试!', {shift: 6});
                return;
            }
            $(this).addClass('select').siblings('.select').removeClass('select');
            var input_navigator = '#navigator-' + id + '-json';
            if($(input_navigator).length) {
                init_lefter_navigator($.parseJSON($(input_navigator).val()));
                return true;
            }
            var json_url = '<?= Url::to(['@web/welcome/sub-navigator']) ?>';
            $.post(json_url, {id: id, submit: 'json', _csrf: $('meta[name=csrf-token]').attr('content')}, function(ret_data) {
                var data = ret_data; // $.parseJSON(ret_data);
                if (data.code == 200) {
                    $('body').append("<input id='" + input_navigator.replace('#', '') + "' type='hidden' value='" + JSON.stringify(data) + "'>");
                    init_lefter_navigator(data);
                }
                else {
                    layer.msg(data.message, {shift: 6});
                }
            });
        });
        // 根据url重置左侧菜单栏
        function init_lefter_navigator(data)
        {
            data.controller = $('#navigator .cate.select').data('controller');
            if (data.code == 200) {
                $('#pg-lefter .box-title').html($('#navigator .cate.select').html() + ' <i class="icon-double-angle-down"></i>');
                var lefter_html = template('lefter-template', data);
                if (lefter_html) {
                    $('#left-navigator').html(lefter_html);
                    if (data.controller == $('#navigator').data('controller')) {
                        $('.sn-' + $('#navigator').data('action').replace('\\', '-').replace('/', '-')).addClass('select').find('a').attr('href', 'javascript:;');
                    }
                }
                else {
                    $('#left-navigator').html('<li><a><i class="icon-ban-circle"></i> 此导航暂不可用</a></li>');
                }
            }
        }
        if ($('#navigator .active').length) {
            $('#navigator .active').click();
        }
        else {
            $('#navigator .cate:first').click();
        }
    });
</script>
<header id="pg-header">
    <div id="color-header">
        <div class="content">
            <div id="site-name">
                <div style="float:right;">
                    <div class="drop-down site-line" id="login-name">
                        <a class="down-button" href="javascript:;"><i class="icon-user"></i> <?= Html::encode(Yii::$app->admin['login_name']) ?> <i class="icon-chevron-down"></i></a>
                        <ul class="show-detail">
                            <li><a href="<?= Url::to('@web/welcome/personal-data') ?>"><i class="icon-asterisk"></i> 个人档案</a></li>
                            <li><a href="<?= Url::to('@web/welcome/change-password') ?>"><i class="icon-key"></i> 更改密码</a></li>
                        </ul>
                    </div>
                    <a class="site-line" href="<?= Url::to('@web/welcome/index') ?>"><i class="icon-home"></i> 首页</a>
                    <a class="site-line" href="<?= Url::to('@web/welcome/logout') ?>"><i class="icon-signout"></i> 退出</a>
                </div>
                <h3 id="company"><?= $this->context->module->name ?></h3>
            </div>
            <ul id="navigator" data-controller="<?= Html::encode(Yii::$app->controller->navigator['controller']) ?>" data-action="<?= Html::encode(Yii::$app->controller->navigator['action']) ?>">
                <!-- li class="cate" data-controller="site" data-id="home"><i class="icon-flag"></i> 管理中心</li -->
            <?php
                $navigators = Navigator::getHeader();
                foreach($navigators as $navigator) {
                    echo '<li class="cate';
                    echo (Yii::$app->controller->navigator['controller'] == $navigator['controller']) ? ' active' : '';
                    echo '" data-controller="'. Html::encode($navigator['controller']) .'" data-id="'. $navigator['id'] .'"><i class="'.Html::encode($navigator['icon_class']).'"></i> '. Html::encode($navigator['title']) .'</li>';
                }
            ?>
            </ul>
        </div>
    </div>
</header>

<div class="content" id="pg-contenter">
    <div id="pg-lefter">
        <div class="box-title">二级导航栏</div>
        <ul id="left-navigator">
            <li><a><i class="icon-spinner icon-spin"></i> 初始化 ...</a></li>
        </ul>
    </div>
    <script id="lefter-template" type="text/html">
        {{each navigators as item key}}
        <li class="sn-{{item.controller.replace('/', '-')}}"><a href="/{{if item.controller.indexOf('/') < 0}}{{controller}}/{{/if}}{{item.controller}}" target="{{item.target}}"><i class="{{item.icon_class}}"></i> {{item.title}}</a></li>
        {{/each}}
    </script>
    <div class="fixed" id="pg-righter">
        <div class="box-title" id="break-crumbs">
            <i class="icon-home"></i>&nbsp;<a href="<?= Url::to('@web/welcome/index') ?>"><?= $this->context->module->name ?></a>&nbsp;
            <?php if( ! empty($this->crumbs)) {
                foreach($this->crumbs as $crumbs) {
                    if($crumbs['url']) {
                        echo "<i class=\"icon-double-angle-right\"></i>&nbsp;<a href=\"{$crumbs['url']}\">{$crumbs['title']}</a>&nbsp;";
                    }
                    else {
                        echo "<i class=\"icon-double-angle-right\"></i>&nbsp;{$crumbs['title']}&nbsp;";
                    }
                }
            } ?>
            <i class="icon-double-angle-right"></i>&nbsp;<?= $this->title ?>
        </div>
        <?= $content ?>
    </div>
    <div class="clear"></div>
</div>

<footer id="pg-footer">
    <div class="content">
        <p class="pull-left">&copy;  <?= date('Y') ?></p>
        <p class="pull-right">powered by flydany</p>
    </div>
</footer>

<script>
    // 页面加载完毕之后的弹窗信息
    $(document).ready(function() {
        var isAlert = '<?= Yii::$app->controller->isAlert ?>';
        var code = '<?= Yii::$app->controller->status['code'] ?>';
        if (isAlert == 'true' || isAlert == '1') {
            if (code == '<?= SuccessCode ?>') {
                layer.msg('<?= Yii::$app->controller->status['message'] ?>', {offset: 'top'});
            }
            else {
                layer.msg('<?= Yii::$app->controller->status['message'] ?>', {offset: 'top'});
            }
        }
    });
</script>

<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
